import logging
import os
from PyCmpltrtok.common import get_dir_name_ext

DIR, BASE, EXT = get_dir_name_ext(os.path.abspath(__file__))
PATH = os.path.join(DIR, 'blog_en_handlers.tmp.log')

DEFAULT_FORMAT = "%(levelname)s:%(name)s:%(message)s"
LOG_FORMAT = "%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(name)s: %(message)s"

logger = logging.getLogger(__name__)

stream_handler = logging.StreamHandler()
stream_handler.setFormatter(logging.Formatter(DEFAULT_FORMAT))

file_handler = logging.FileHandler(PATH)
file_handler.setFormatter(logging.Formatter(LOG_FORMAT))

stream_handler.setLevel(logging.DEBUG)
file_handler.setLevel(logging.WARNING)
logger.setLevel(logging.DEBUG)  # Critical: logger level must be larger than any handler's

logger.addHandler(stream_handler)
logger.addHandler(file_handler)

if __name__ == '__main__':

    logger.warning('Warning msg! 警告日志')
    logger.debug('调试日志 - Debug log.')

    logger.warning('Warning msg! 警告日志 02')
    logger.debug('调试日志 - Debug log 02.')
